﻿/*
' Copyright (c) 2013  Christoc.com
'  All rights reserved.
' 
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
' DEALINGS IN THE SOFTWARE.
' 
*/

using System;
using System.IO;
using System.Net;
using System.Net.Mail;
using System.Security.Cryptography;
using System.Text;
using System.Web.UI.WebControls;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Modules.Actions;
using DotNetNuke.Services.Localization;
using DotNetNuke.Security;
using System.Text.RegularExpressions;
using DotNetNuke.Services.Log.EventLog;
using System.Net.Http;
using Newtonsoft.Json;






namespace GP_Hosting_ContactForm
{

    public class PasswordEncrypter : PortalModuleBase
    {
        static readonly string PasswordHash = "####GPH0sting_Is_The_B3st_DNN_Hosting_Pr0vider####";
        static readonly string SaltKey = "$@LTY&KEY#";
        static readonly string VIKey = "@1B2c3D4e5F61g7H8#";


        public static string Encrypt(string plainText)
        {
            byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText);

            byte[] keyBytes = new Rfc2898DeriveBytes(PasswordHash, Encoding.ASCII.GetBytes(SaltKey)).GetBytes(256 / 8);
            var symmetricKey = new RijndaelManaged() { Mode = CipherMode.CBC, Padding = PaddingMode.Zeros };
            var encryptor = symmetricKey.CreateEncryptor(keyBytes, Encoding.ASCII.GetBytes(VIKey));

            byte[] cipherTextBytes;

            using (var memoryStream = new MemoryStream())
            {
                using (var cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write))
                {
                    cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length);
                    cryptoStream.FlushFinalBlock();
                    cipherTextBytes = memoryStream.ToArray();
                    cryptoStream.Close();
                }
                memoryStream.Close();
            }
            return Convert.ToBase64String(cipherTextBytes);
        }



        public static string Decrypt(string encryptedText)
        {
            byte[] cipherTextBytes = Convert.FromBase64String(encryptedText);
            byte[] keyBytes = new Rfc2898DeriveBytes(PasswordHash, Encoding.ASCII.GetBytes(SaltKey)).GetBytes(256 / 8);
            var symmetricKey = new RijndaelManaged() { Mode = CipherMode.CBC, Padding = PaddingMode.None };

            var decryptor = symmetricKey.CreateDecryptor(keyBytes, Encoding.ASCII.GetBytes(VIKey));
            var memoryStream = new MemoryStream(cipherTextBytes);
            var cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read);
            byte[] plainTextBytes = new byte[cipherTextBytes.Length];

            int decryptedByteCount = cryptoStream.Read(plainTextBytes, 0, plainTextBytes.Length);
            memoryStream.Close();
            cryptoStream.Close();
            return Encoding.UTF8.GetString(plainTextBytes, 0, decryptedByteCount).TrimEnd("\0".ToCharArray());
        }


    }



    public class GP_Hosting_ContactFormModuleBase : PortalModuleBase
    {



        #region Properties
        private string _smtpserver;
        public string SMTPServerSettings
        {
            get
            {
                _smtpserver = string.Empty;
                if (Settings.Contains("SMTPServer"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["SMTPServer"].ToString()))
                    {
                        _smtpserver = Settings["SMTPServer"].ToString();
                    }
                }
                return _smtpserver;
            }
            set { _smtpserver = value; }
        }
        private string _regexforemail;
        public string RegexForEmail
        {
            get
            {
                _regexforemail = @"[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?";
                return _regexforemail;
            }
            set { _regexforemail = value; }
        }
        private bool _isbcc;
        public bool IsBCC
        {
            get
            {
                if (Settings.Contains("BccAddress"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["BccAddress"].ToString()))
                    {
                        Regex emailvalidate = new Regex(RegexForEmail);
                        if (emailvalidate.IsMatch(Settings["BccAddress"].ToString()))
                        {
                            return _isbcc = true;
                        }
                    }
                }
                else
                {
                    _isbcc = false;
                }

                return _isbcc;
            }
            set { _isbcc = value; }
        }
        private string _bccaddress;
        public string GetBccAddress
        {
            get
            {
                _bccaddress = string.Empty;
                if (Settings.Contains("BccAddress"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["BccAddress"].ToString()))
                    {
                        _bccaddress = Settings["BccAddress"].ToString();
                    }
                }

                return _bccaddress;
            }
            set { _bccaddress = value; }
        }
        private string _emailsubject;
        public string GetEmailsubject
        {
            get
            {
                _emailsubject = string.Empty;
                if (Settings.Contains("Subject"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["Subject"].ToString()))
                    {
                        _emailsubject = Settings["Subject"].ToString();
                    }
                }
                return _emailsubject;
            }
            set { _emailsubject = value; }
        }
        private string _toaddress;
        public string GetToAddress
        {
            get
            {
                _toaddress = string.Empty;
                if (Settings.Contains("ToAddress"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["ToAddress"].ToString()))
                    {
                        _toaddress = Settings["ToAddress"].ToString();
                    }
                }

                return _toaddress;
            }
            set { _toaddress = value; }
        }
        private string _fromaddress;
        public string GetFromAddress
        {
            get
            {
                _fromaddress = string.Empty;
                if (Settings.Contains("FromAddress"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["FromAddress"].ToString()))
                    {
                        _fromaddress = Settings["FromAddress"].ToString();
                    }
                }
                return _fromaddress;
            }
            set { _fromaddress = value; }
        }
        private bool _namefield;
        public bool ValidateNameField
        {
            get
            {
                _namefield = false;

                if (Settings.Contains("NameRequired"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["NameRequired"].ToString()))
                    {
                        bool.TryParse(Settings["NameRequired"].ToString(), out _namefield);
                    }
                }
                return _namefield;


            }
            set { _namefield = value; }
        }
        private bool _surnamefield;
        public bool ValidateSurnameField
        {
            get
            {
                _surnamefield = false;
                if (Settings.Contains("SurnameRequired"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["SurnameRequired"].ToString()))
                    {
                        bool.TryParse(Settings["SurnameRequired"].ToString(), out _surnamefield);
                    }
                }

                return _surnamefield;
            }
            set { _surnamefield = value; }
        }
        private bool _contactnumber;
        public bool ValidateContactNumber
        {
            get
            {
                _contactnumber = false;
                if (Settings.Contains("ContactRequired"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["ContactRequired"].ToString()))
                    {
                        bool.TryParse(Settings["ContactRequired"].ToString(), out _contactnumber);
                    }
                }

                return _contactnumber;
            }
            set { _contactnumber = value; }
        }
        private bool _validateemail;
        public bool ValidateEmailField
        {
            get
            {
                _validateemail = false;

                if (!string.IsNullOrWhiteSpace(RegexEmail))
                {
                    _validateemail = true;
                }

                return _validateemail;
            }
            set { _validateemail = value; }
        }
        private bool _messagevalidate;
        public bool ValidateMessageField
        {
            get
            {
                _messagevalidate = false;
                if (Settings.Contains("MessageRequired"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["MessageRequired"].ToString()))
                    {
                        bool.TryParse(Settings["MessageRequired"].ToString(), out _messagevalidate);
                    }
                }
                return _messagevalidate;
            }
            set { _messagevalidate = value; }
        }
        private bool _enablerecaptcha;
        public bool EnableGooglereCaptcha
        {
            get
            {
                _enablerecaptcha = false;
                if (Settings.Contains("EnableGooglereCaptcha"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["EnableGooglereCaptcha"].ToString()))
                    {
                        bool.TryParse(Settings["EnableGooglereCaptcha"].ToString(), out _enablerecaptcha);
                    }
                }
                return _enablerecaptcha;
            }
            set { _enablerecaptcha = value; }
        }
        public string DefaultEmailRegex()
        {
            return @"[-0-9a-zA-Z.+_]+@[-0-9a-zA-Z.+_]+\.[a-zA-Z]{2,4}";
        }
        private string _emailregex;
        public string RegexEmail
        {
            get
            {
                _emailregex = string.Empty;


                if (Settings.Contains("RegexEmail"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["RegexEmail"].ToString()))
                    {
                        _emailregex = Settings["RegexEmail"].ToString();
                    }
                    else
                    {
                        _emailregex = DefaultEmailRegex();
                    }
                }
                else
                {
                    _emailregex = DefaultEmailRegex();
                }

                return _emailregex;
            }
            set { _emailregex = value; }
        }
        private string _recaptchaprivatekey;
        public string GetreCaptchaPrivateKey
        {
            get
            {
                _recaptchaprivatekey = string.Empty;

                if (Settings.Contains("reCaptchaPrivateKey"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["reCaptchaPrivateKey"].ToString()))
                    {
                        _recaptchaprivatekey = Settings["reCaptchaPrivateKey"].ToString();
                    }
                }
                return _recaptchaprivatekey;
            }
            set
            {
                _recaptchaprivatekey = value;
            }
        }
        private string _recaptchapublickey;
        public string GetreCaptchaPublicKey
        {
            get
            {
                _recaptchapublickey = string.Empty;

                if (Settings.Contains("reCaptchaPublicKey"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["reCaptchaPublicKey"].ToString()))
                    {
                        _recaptchapublickey = Settings["reCaptchaPublicKey"].ToString();
                    }
                }

                return _recaptchapublickey;
            }
            set { _recaptchapublickey = value; }
        }
        private string _recaptchatheme;
        public string GetreCaptchaTheme
        {
            get
            {
                _recaptchatheme = string.Empty;
                if (Settings.Contains("reCaptchaTheme"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["reCaptchaTheme"].ToString()))
                    {
                        _recaptchatheme = Settings["reCaptchaTheme"].ToString();
                    }
                }

                return _recaptchatheme;
            }
            set { _recaptchatheme = value; }
        }
        private bool _usednnsettings;
        public bool UseDnnSettings
        {
            get
            {
                _usednnsettings = false;

                if (Settings.Contains("DNNSMTPServer"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["DNNSMTPServer"].ToString()))
                    {
                        bool.TryParse(Settings["DNNSMTPServer"].ToString(), out _usednnsettings);
                    }
                }
                return _usednnsettings;
            }
            set { _usednnsettings = value; }
        }
        private string _blankrecaptcha;
        public string BlankRecaptcha
        {
            get
            {
                _blankrecaptcha = string.Empty;
                if (Settings.Contains("reCaptchaThemeblank"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["reCaptchaThemeblank"].ToString()))
                    {
                        _blankrecaptcha = Settings["reCaptchaThemeblank"].ToString();
                    }

                }

                return _blankrecaptcha;
            }
            set { _blankrecaptcha = value; }
        }
        private string _incorrectcaptcha;
        public string IncorrectCaptcha
        {
            get
            {
                _incorrectcaptcha = string.Empty;

                if (Settings.Contains("reCaptchaThemeincorret"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["reCaptchaThemeincorret"].ToString()))
                    {
                        _incorrectcaptcha = Settings["reCaptchaThemeincorret"].ToString();
                    }

                }

                return _incorrectcaptcha;
            }
            set { _incorrectcaptcha = value; }
        }
        private string _nameerror;

        public string NameError
        {
            get
            {

                _nameerror = string.Empty;
                if (Settings.Contains("NameMSG"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["NameMSG"].ToString()))
                    {
                        _nameerror = Settings["NameMSG"].ToString();
                    }

                }

                return _nameerror;
            }
            set { _nameerror = value; }
        }

        private string _surnameerror;

        public string SurnameError
        {
            get
            {
                _surnameerror = string.Empty;

                if (Settings.Contains("SurnameMSG"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["SurnameMSG"].ToString()))
                    {
                        _surnameerror = Settings["SurnameMSG"].ToString();
                    }

                }
                return _surnameerror;
            }
            set { _surnameerror = value; }
        }

        private string _contacterror;

        public string ContactError
        {
            get
            {
                _contacterror = string.Empty;


                if (Settings.Contains("ContactMSG"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["ContactMSG"].ToString()))
                    {
                        _contacterror = Settings["ContactMSG"].ToString();
                    }

                }
                return _contacterror;
            }
            set { _contacterror = value; }
        }

        private string _messageerror;

        public string MessageError
        {
            get
            {
                _messageerror = string.Empty;
                if (Settings.Contains("MessageMSG"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["MessageMSG"].ToString()))
                    {
                        _messageerror = Settings["MessageMSG"].ToString();
                    }

                }
                return _messageerror;
            }
            set { _messageerror = value; }
        }

        private string _emailerror;

        public string EmailErrorMSG
        {
            get
            {

                _emailerror = string.Empty;
                if (Settings.Contains("EmailMSG"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["EmailMSG"].ToString()))
                    {
                        _emailerror = Settings["EmailMSG"].ToString();
                    }

                }

                return _emailerror;
            }
            set { _emailerror = value; }
        }

        private string _replyemailtemplate;
        public string ReplyEmailTemplate
        {
            get
            {

                _replyemailtemplate = string.Empty;
                if (Settings.Contains("ReplyEmailTemplate"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["ReplyEmailTemplate"].ToString()))
                    {
                        _replyemailtemplate = Settings["ReplyEmailTemplate"].ToString();
                    }
                }
                return _replyemailtemplate;
            }
            set { _replyemailtemplate = value; }
        }

        private bool _enablereply;
        public bool EnableReplyMail
        {
            get
            {
                _enablereply = false;
                if (Settings.Contains("SendReply"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["SendReply"].ToString()))
                    {
                        bool.TryParse(Settings["SendReply"].ToString(), out _enablereply);
                    }
                }

                return _enablereply;
            }
            set { _enablereply = value; }
        }

        private string _replyfromaddress;
        public string GetReplyFromAddress
        {
            get
            {
                _replyfromaddress = string.Empty;
                if (Settings.Contains("AutoReplyFromAddress"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["AutoReplyFromAddress"].ToString()))
                    {
                        _replyfromaddress = Settings["AutoReplyFromAddress"].ToString();
                    }
                }
                return _replyfromaddress;
            }
            set { _replyfromaddress = value; }
        }
        private string _smtpusername;
        public string SmtpUsername
        {
            get
            {
                _smtpusername = string.Empty;
                if (Settings.Contains("SMTPUsername"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["SMTPUsername"].ToString()))
                    {
                        _smtpusername = Settings["SMTPUsername"].ToString();
                    }
                }
                return _smtpusername;
            }
            set { _smtpusername = value; }
        }
        private string _smtppassword;
        public string SmtpPassword
        {
            get
            {
                _smtppassword = string.Empty;
                if (Settings.Contains("SMTPPassword"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["SMTPPassword"].ToString()))
                    {
                        _smtppassword = Settings["SMTPPassword"].ToString();
                    }
                }

                return _smtppassword;
            }
            set { _smtppassword = value; }
        }

        private string _smtpportnum;
        public string SmtpPortnum
        {
            get
            {
                _smtpportnum = string.Empty;
                if (Settings.Contains("SMTPPort"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["SMTPPort"].ToString()))
                    {
                        _smtpportnum = Settings["SMTPPort"].ToString();
                    }
                }
                return _smtpportnum;
            }
            set { _smtpportnum = value; }
        }

        private bool _profanitycheck;

        public bool ProfanityCheck
        {
            get
            {
                _profanitycheck = false;

                if (Settings.Contains("EnableProfanity"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["EnableProfanity"].ToString()))
                    {
                        bool.TryParse(Settings["EnableProfanity"].ToString(), out _profanitycheck);
                    }
                }

                return _profanitycheck;
            }
            set { _profanitycheck = value; }
        }

        private string _profanitymsg;

        public string ProfanityMSG
        {
            get
            {
                _profanitymsg = string.Empty;
                if (Settings.Contains("ProfanityMessage"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["ProfanityMessage"].ToString()))
                    {
                        _profanitymsg = Settings["ProfanityMessage"].ToString();
                    }

                }

                return _profanitymsg;
            }
            set { _profanitymsg = value; }
        }

        private string _emailsentok;

        public string EmailSentOK
        {
            get
            {
                _emailsentok = string.Empty;

                if (Settings.Contains("EMAILSENT"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["EMAILSENT"].ToString()))
                    {
                        _emailsentok = Settings["EMAILSENT"].ToString();
                    }

                }

                return _emailsentok;
            }
            set { _emailsentok = value; }
        }


        private string _emailnotsent;

        public string EmailNotSent
        {
            get
            {
                _emailnotsent = string.Empty;
                if (Settings.Contains("EMAILNOTSENT"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["EMAILNOTSENT"].ToString()))
                    {
                        _emailnotsent = Settings["EMAILNOTSENT"].ToString();
                    }

                }

                return _emailnotsent;
            }
            set { _emailnotsent = value; }
        }

        private string _autoreplyemailsubjecy;

        public string AutoReplyEmailSubject
        {
            get
            {
                _autoreplyemailsubjecy = string.Empty;

                if (Settings.Contains("AutoReplySubject"))
                {
                    if (!string.IsNullOrWhiteSpace(Settings["AutoReplySubject"].ToString()))
                    {
                        _autoreplyemailsubjecy = Settings["AutoReplySubject"].ToString();
                    }

                }

                return _autoreplyemailsubjecy;
            }
            set { _autoreplyemailsubjecy = value; }
        }
        #endregion


        public bool SendEmail(EmailObject email)
        {
            var Log = new EventLogController();
            try
            {
                //Create stringbuilder to build email body
                StringBuilder strMail = new StringBuilder();

                //Create Body for Email
                strMail.Append("<table width=\"600px\" cellpadding=\"3\" cellspacing=\"3\">");
                strMail.Append("<tr><td valign=\"top\" style=\"font-size:11pt;font-family:Arial;\">Name: " + email.name + "</td></tr>");
                strMail.Append("<tr><td valign=\"top\" style=\"font-size:11pt;font-family:Arial;\">Surname: " + email.surname + "</td></tr>");
                strMail.Append("<tr><td valign=\"top\" style=\"font-size:11pt;font-family:Arial;\">Contact No.: " + email.contactnumber + "</td></tr>");
                strMail.Append("<tr><td valign=\"top\" style=\"font-size:11pt;font-family:Arial;\">Email: " + email.fromaddress + "</td></tr>");
                strMail.Append("<tr><td valign=\"top\" style=\"font-size:11pt;font-family:Arial;\">Message: <br /> <br /> " + email.message + "</td></tr>");
                strMail.Append("</table>");
                strMail.Append("<br />");
                strMail.Append("You may reply to this email by clicking on the reply button on your email application");

                //Create Mail Object
                MailMessage mail = new MailMessage();

                //Create To Address
                // MailAddress To = new MailAddress(_toAddress.ToString());


                //Create From Address
                MailAddress FromA = new MailAddress(GetFromAddress);

                //Create Reply Address
                // MailAddress replytosender = new MailAddress(txtemail.Text.ToString());

                //Create Bcc Address
                if (IsBCC)
                {
                    MailAddress bcc = new MailAddress(GetBccAddress);
                    mail.Bcc.Add(bcc);
                }
                //Set Email to HTML Body
                mail.IsBodyHtml = true;

                //Subject
                mail.Subject = GetEmailsubject;

                //Add To Recipients
                mail.To.Add(GetToAddress);

                //Add Sender
                mail.From = FromA;

                //Add Body Text
                mail.Body = strMail.ToString();

                //Add Bcc

                //Add Reply Address
                mail.ReplyTo = new MailAddress(email.fromaddress);

                //SMTP Information

                SmtpClient SmtpMail = new SmtpClient(SMTPServerSettings);

                //Send Email
                SmtpMail.Credentials = new System.Net.NetworkCredential(SmtpUsername, PasswordEncrypter.Decrypt(SmtpPassword));
                SmtpMail.Port = Convert.ToInt32(SmtpPortnum);
                SmtpMail.Send(mail);
                mail.Dispose();
                Log.AddLog("GP Hosting Contact Form", "Email Sent", PortalSettings, -1, EventLogController.EventLogType.ADMIN_ALERT);
                return true;

            }


            catch (Exception SendError)
            {
                Exceptions.ProcessModuleLoadException(this, SendError);
                return false;
            }
        }

        public bool SendEmailUsingDnn(string FromAddress, string SenderAddress, string ToAddress, string Subject, String Body)
        {
            try
            {
                DotNetNuke.Services.Mail.Mail.SendEmail(FromAddress, SenderAddress, ToAddress, Subject, Body);
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }

        public bool ReplyToUser(EmailObject email)
        {
            var Log = new EventLogController();
            try
            {
                //Create stringbuilder to build email body
                StringBuilder strMail = new StringBuilder();

                //Create Body for Email
                strMail.Append(TokenMsg(ReplyEmailTemplate, email.name, email.surname, email.contactnumber, email.fromaddress));

                //Create Mail Object
                MailMessage mail = new MailMessage();

                //Create To Address


                //Create From Address
                MailAddress FromA = new MailAddress(GetReplyFromAddress);


                mail.IsBodyHtml = true;

                //Subject
                mail.Subject = AutoReplyEmailSubject;

                //Add To Recipients
                mail.To.Add(email.fromaddress);

                //Add Sender
                mail.From = FromA;

                //Add Body Text
                mail.Body = strMail.ToString();


                //SMTP Information

                SmtpClient SmtpMail = new SmtpClient(SMTPServerSettings);

                //Send Email
                SmtpMail.Credentials = new System.Net.NetworkCredential(SmtpUsername, PasswordEncrypter.Decrypt(SmtpPassword));
                SmtpMail.Port = Convert.ToInt32(SmtpPortnum);
                SmtpMail.Send(mail);
                mail.Dispose();
                Log.AddLog("GP Hosting Contact Form", "Reply Email Sent", PortalSettings, -1, EventLogController.EventLogType.ADMIN_ALERT);
                return true;
            }


            catch (Exception ex)
            {
                return false;
            }

        }

        public StringBuilder TokenMsg(string replymsg, string name, string surname, string contact, string email)
        {
            var stringb = new StringBuilder();
            stringb.Append(replymsg);
            stringb.Replace("[NAME]", name);
            stringb.Replace("[SURNAME]", surname);
            stringb.Replace("[CONTACT]", contact);
            stringb.Replace("[EMAIL]", email);
            var converttext = Server.HtmlDecode(stringb.ToString());
            stringb.Clear();
            stringb.Append(converttext);

            return stringb;
        }

        public static bool profanityChecker(string message)
        {

            var url = @"http://www.wdyl.com/profanity?q=" + message;
            WebClient webClient = new WebClient();
            Stream stream = webClient.OpenRead(url);
            StreamReader reader = new StreamReader(stream);
            var request = reader.ReadToEnd();
            var outObject = JsonConvert.DeserializeObject<profanitycheck>(request);
            return outObject.Response;
        }
        public class profanitycheck
        {
            public bool Response { get; set; }
        }


    }
}